package com.keyancompany.zhongbaopingtai.activity;


import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.keyancompany.zhongbaopingtai.Constants;
import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.TeamCreateActivity;
import com.keyancompany.zhongbaopingtai.adapter.IFragmentPagerAdapter;
import com.keyancompany.zhongbaopingtai.fragment.MyTeamFragment;
import com.keyancompany.zhongbaopingtai.utils.IntentUtils;
import com.keyancompany.zhongbaopingtai.utils.T;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.BindString;

/**
 * 我的团队
 */
public class MyTeamActivity extends BaseActivity {
    @BindString(R.string.my_team_text)
    String title;
    @Bind(R.id.toolbar)
    Toolbar toolbar;

    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.complaint_viewpager)
    ViewPager complaintViewpager;


    @Override
    protected int getContentViewId() {
        return R.layout.activity_complaint;
    }

    @Override
    protected int getMenuId() {
        return R.menu.publish_package_menu;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // 动态设置ToolBar状态
        switch (tabLayout.getSelectedTabPosition()) {
            case 0:
                menu.findItem(R.id.action_publish_package).setVisible(false);
                break;
            case 1:
                menu.findItem(R.id.action_publish_package).setVisible(true);
                break;
        }
        return super.onPrepareOptionsMenu(menu);
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.action_publish_package) {
            IntentUtils.startActivity(mContext, TeamCreateActivity.class);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void initToolBar() {
        initToolBar(toolbar, title);

//        listView.setAdapter(new TeamAdapter(mContext));


    }

    @Override
    protected void setUpViews() {
        tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
        tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
        List<Fragment> tcf = new ArrayList<>();
        tcf.add(new MyTeamFragment().newInstance(1));
        tcf.add(new MyTeamFragment().newInstance(0));
        IFragmentPagerAdapter pagerAdapter = new IFragmentPagerAdapter(getSupportFragmentManager(), tcf);
        pagerAdapter.setTitles(new String[]{"临时团队", "我的团队"});
        complaintViewpager.setAdapter(pagerAdapter);
        tabLayout.setupWithViewPager(complaintViewpager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);

        complaintViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                if(position == 1){
                    toolbar.getMenu().findItem(R.id.action_publish_package).setVisible(true);
                }else{
                    toolbar.getMenu().findItem(R.id.action_publish_package).setVisible(false);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

}
